import { each, throttle } from 'lodash-es';

import RectModel from './RectModel';
import CircleModel from './CircleModel';
import GraphModel from './GraphModel';

const modelMap = new Map();

const setupModel = (config) => {
  const graphModel = new GraphModel();

  each(config.nodes, node => {
    const model = modelMap.get(node.type);
    if (!model) {
      throw new Error(`未注册${node.type}的model`);
    }
    console.log(model, node);
    graphModel.nodes.push(new model(node));
  });

  return {
    graphModel,
  };
}

const registerModel = (key, model) => {
  modelMap.set(key, model);
}

registerModel('rect', RectModel);
registerModel('circle', CircleModel);

export {
  setupModel,
  registerModel,
};
